﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PhoneBook;

namespace PhoneBook_PC2
{
    public class Book
    {
        PhoneBook.PhoneBook phoneBook;

        public Book()
        {
            phoneBook = new PhoneBook.PhoneBook();
        }

        public void addContact(Contact c)
        {
            phoneBook.addContact(c);
        }

        public void deleteContact(Contact c)
        {
            phoneBook.deleteContact(c);
        }

        public void modifyContact(Contact c1, Contact c2) {
            phoneBook.modifyContact(c1, c2);
        }

        public void addContactToGroup(Group g, Contact c)
        {
            g.addToGroup(c);
        }

        public void removeContactFromGroup(Group g, Contact c)
        {
            g.removeFromGroup(c);
        }

        public List<String> getListGroups()
        {
            List<String> groupNames = new List<String>();
            groupNames = phoneBook.getGroupNames();
            return groupNames;

        }

        public List<Contact> getListGroupContacts(String groupName)
        {
            List<Contact> groupContacts = new List<Contact>();
            groupContacts = phoneBook.getContactsByGroup(groupName);
            return groupContacts;
        }

        public List<Contact> getContacts()
        {
            List<Contact> contacts = new List<Contact>();
            contacts = phoneBook.getAllContacts();
            return contacts;
        }

        public Contact getContact(String firstName, String lastName)
        {
            List<Contact> contacts = this.getContacts();
            foreach (Contact c in contacts)
            {
                if (c.getPerson().getFirstname().Equals(firstName) && c.getPerson().getLastname().Equals(lastName))
                    return c;
            }
            return null;
        }

        public List<Contact> searchContact(String stringContact)
        {
            return phoneBook.searchContact(stringContact);
        }

       public Group getGroup(String groupName)
        {
            List<Group> groups = phoneBook.getAllGroups();
            foreach (Group g in groups)
            {
                
                if (g.getGroupName().Equals(groupName) )
                    return g;
            }
            return null;
        }
    }
}